package zing.downloader.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HtmlUtil {

    public static String compoundLinkBySongId(String songId) {
        return Constant.BASE_URL + songId;
    }

    public static String decodeUrlString(String encodedUrl) {
        try {
            return URLDecoder.decode(encodedUrl, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return encodedUrl;
        }
    }

    public static String getQueryString(String url, String key) {
        if (url == null || key == null) {
            return null;
        }
        Pattern p = Pattern.compile(String.format("[?&]%s=([^?&]+)", key));
        Matcher m = p.matcher(url);
        return m.find() ? m.group(1) : null;
    }

}
